package org.flash.net{
    import flash.events.*;
    import flash.net.*;

	/**
	 * 重写的URLLoader类
	 * 参数url,回调函数fun 
	 * 
	 */	
    public class URLLoaderChild extends URLLoader {
        private var _complete:Function;

        public function URLLoaderChild(url:String, fun:Function = null) {
            this._complete = fun;
            this.load(new URLRequest(url));
        }
		
        override public function load(request:URLRequest) : void {
			super.load(request);
            this.addEventListener(IOErrorEvent.IO_ERROR, this.loadError);
			this.addEventListener(Event.COMPLETE, this.loadComplete);
        }
		/**加载完成*/
        private function loadComplete(event:Event) : void {
            if (this._complete != null){
                this._complete(this);	 //当前对象作为传入函数参数
            }
            this.depose();
        }
		/**消毁*/
        private function depose() : void {
            removeEventListener(IOErrorEvent.IO_ERROR, this.loadError);
            removeEventListener(Event.COMPLETE, this.loadComplete);
            this._complete = null;
        }
		/**IO出错*/
		private function loadError(event:IOErrorEvent) : void {
			trace("URLLoaderChild Net Load Path error...");
			return;
		}
    }
}
